package mju.cn.twoweek.main;

import mju.cn.twoweek.bean.Role;
import mju.cn.twoweek.mapper.RoleMapper;
import mju.cn.twoweek.utils.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.logging.Logger;

/**
 * @program: java-ee_31
 * @description:
 * @author: HP
 * @time: 2020/9/21 11:39
 */
public class Chapter03Main {
    public static void main(String[] args) {
        Logger log =Logger.getLogger(String.valueOf(Chapter03Main.class));
        SqlSession sqlSession= null;
        try {
            sqlSession = SqlSessionFactoryUtils.openSqlSession();
            RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);//获取接口里面的对象
            roleMapper.insertRole(new Role(31,"项目经理","Manage projects"));
            Role role = roleMapper.getRole(1L);
//            roleMapper.deleteRole(1L);

            log.info(role.getRoleName());
    }finally {
            if(sqlSession != null){
                sqlSession.close();
            }
        }

}

//public class Chapter03Main {
//
//    public static void main(String[] args) {
//        testInsert();
//    }
//
//    public static void testInsert() {
//        Role role = new Role();
//        role.setRoleName("项目经理");
//        role.setNote("Manage projects");
//        SqlSession sqlSession = SqlSessionFactoryUtils.openSqlSession();
//        RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);//sql语句和驱动的连接
//        roleMapper.insertRole(role);//执行sql语句
//        sqlSession.commit();
//        if (sqlSession != null) sqlSession.close();
//    }
}
